<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="keywords" content="广东国防教育学会">
    <meta name="description" content="广东国防教育学会">
    <title>广东国防教育学会</title>
    <link rel="shortcut icon" href="/Public/Admin/img/favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="/Public/Admin/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" href="/Public/Admin/bootstrap_validator-0.4.5/dist/css/bootstrapValidator.css"/>
    <link href="/Public/Admin/css/animate.min.css" rel="stylesheet">
    <link href="/Public/Admin/plugins/iCheck/all.css" rel="stylesheet">
    <style>
		/* *{
			color:#000;
		} */
		.btn{
		 	 padding: 5px 8px;
		 	 /* border-radius: 0px; */
			font-size:12px;
			margin-bottom:0px;
		}
		.table{
	    	width: 100%;
		}
		.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
			padding:0px 5px;
			/*text-align: center;*/
			vertical-align: middle!important;
		}
		.form-control{
			font-size: 12px;
		}
		#file-pretty button{
			padding: 7.5px 13px;
		}
		p{
	   		 margin: 0 0;
		}
		.pagination{
			margin:0px 0px;
		}
		.select_width{
			width:100px;
		}
		.select_no_border{
			border-right: none;
		}
	</style>
</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>分类列表</h5>
						<div class="ibox-tools">
							<a class="collapse-link">
								<i class="fa fa-chevron-up"></i>
							</a>
							<a class="close-link">
								<i class="fa fa-times"></i>
							</a>
						</div>
					</div>
					<div class="ibox-content">
						<div class="">
							<a href="#" class="btn btn-primary"
								aria-controls="messages" role="button" data-toggle="modal"
								data-target="#myModal">
								<span class="fa fa-plus"></span>
								添加分类
							</a>
						</div>
						<br />
						<div class="table-responsive">
							<table class="table table-bordered table-hover"
								id="categoryTable">
								<thead>
									<tr style="background: #f9f9f9;">
										<th>折叠</th>
										<th>分类名称</th>
										<th>所属父级</th>
										<th>分类标题</th>
										<th>排序</th>
										<th>是否显示</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<?php if(is_array($category)): foreach($category as $key=>$data): ?><tr class="level_<?php echo ($data['level']); ?> pid_<?php echo ($data['pid']); ?>"
										cid="<?php echo ($data['cid']); ?>" level="<?php echo ($data['level']); ?>">
										<td>
											<!-- <?php echo ($data['html']); ?>
											<a class='btn btn-primary btn-sm unfold' href="#">+</a> -->
										</td>
										<td style="text-align:left;"><?php echo ($data['html']); echo ($data['cname']); ?></td>
										<td><?php echo ($data['pid']); ?></td>
										<td><?php echo ($data['title']); ?></td>
										<td><?php echo ($data['sort']); ?></td>
										<td>
										<?php if($data['is_display'] == 1): ?>显示
										<?php else: ?>
											隐藏<?php endif; ?>
										</td>
										<td class="center">
											<div class="dropdown">
												<button class="btn btn-primary dropdown-toggle"
													type="button" id="dropdownMenu1" data-toggle="dropdown"
													aria-haspopup="true" aria-expanded="true">
													操作
													<span class="caret"></span>
												</button>
												<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
													<li>
														<a role="button" class="btn btn-primary"
															style="margin-bottom: 0px;" group_id="<?php echo ($data['id']); ?>"
															group_title="<?php echo ($data['title']); ?>" onclick="editGroup(this)"
															href="#">
															<span class="fa fa-edit"></span>
															修改
														</a>
													</li>
													<li>
														<a role="button" class="btn btn-danger"
															style="margin-bottom: 0px;"
															onclick="deleteCategory(this,<?php echo ($data['cid']); ?>)" href="#">
															<span class="fa fa-trash-o"></span>
															删除
														</a>
													</li>
												</ul>
											</div>
										</td>
									</tr><?php endforeach; endif; ?>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">添加分类</h4>
				</div>
				<div class="modal-body">
					<!-- class都是bootstrap定义好的样式，验证是根据input中的name值 -->
					<form action="/Admin/Category/addCategory" method="post" id="defaultForm">

						<div class="form-group">
							<label for="exampleInputMenuName">所属分类</label>
							<select name="pid" style="border-radius: 4px;"
								class="form-control">
								<option value="">顶级分类</option>
							<?php if(is_array($category)): foreach($category as $key=>$data): ?><option value="<?php echo ($data['cid']); ?>"><?php echo ($data['html']); echo ($data['cname']); ?></option><?php endforeach; endif; ?>
							</select>
						</div>

						<div class="form-group">
							<label for="categoryName">分类名称</label>
							<input type="text" name="cname" style="border-radius: 4px;"
								id="categoryName" class="form-control" />
						</div>

						<div class="form-group">
							<label for="categoryTitle">分类标题</label>
							<input type="text" name="title" style="border-radius: 4px;"
								id="categoryTitle" class="form-control" />
						</div>

						<div class="form-group">
							<label for="categoryKeywords">分类关键字</label>
							<input type="text" name="keywords" style="border-radius: 4px;"
								id="categoryKeywords" class="form-control" />
						</div>

						<div class="form-group">
							<label for="categoryDescription">分类描述</label>
							<textarea name="description" style="border-radius: 4px;"
								class="form-control" id="categoryDescription" /></textarea>
						</div>

						<div class="form-group">
							<label for="categorySort">分类排序</label>
							<input type="number" name="sort" style="border-radius: 4px;"
								id="categorySort" class="form-control" />
						</div>

						<div class="form-group">
							<div class="i-check">
								<label for="exampleInputMenuName">是否显示</label>
								&nbsp;&nbsp;
								<input type="radio" name="is_display" value="1"
									checked="checked" />
								显示&nbsp;
								<input type="radio" name="is_display" value="2" />
								隐藏
							</div>
						</div>

						<div class="modal-footer" id="parent_id">
							<button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
							<button type="submit" class="btn btn-primary">提交</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<!-- Modal -->

	
<script src="/Public/Admin/js/jquery.min.js?v=2.1.4"></script>
<script src="/Public/Admin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- <script src="/Public/Admin/js/content.min.js?v=1.0.0"></script> -->
<script type="text/javascript" src="/Public/Admin/bootstrap_validator-0.4.5/dist/js/bootstrapValidator.js"></script>
<script src="/Public/Admin/plugins/layer/layer.js"></script>
<script src="/Public/Admin/plugins/iCheck/icheck.min.js"></script>

<script>
//设置checkbox按钮
$('.i-check').iCheck({
	checkboxClass : "icheckbox_square-green",
	radioClass : "iradio_square-green",
});
</script>

</body>
</html>

	<script>
$(document).ready(function() {
    /**
     * 下面是进行插件初始化
     * 你只需传入相应的键值对
     * */
    $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {/*输入框不同状态，显示图片的样式*/
            	  valid: 'glyphicon glyphicon-ok',
                  invalid: 'glyphicon glyphicon-remove',
                  validating: 'glyphicon glyphicon-refresh'
            },
            fields: {/*验证*/
            	cname: {/*键名username和input name值对应*/
                    message: '分类名称验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '分类名称不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '分类名称长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                title: {/*键名username和input name值对应*/
                    message: '分类标题验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '分类标题不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '分类标题长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                keywords: {/*键名username和input name值对应*/
                    message: '分类关键字验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '分类关键字不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '分类关键字长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                description: {/*键名username和input name值对应*/
                    message: '分类描述验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '分类描述不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 2,
                            max: 30,
                            message: '分类描述长度必须在2到30之间'
                        }/*最后一个没有逗号*/
                    }
                },
                sort: {/*键名username和input name值对应*/
                    message: '排序验证失败',
                    validators: {
                        notEmpty: {/*非空提示*/
                            message: '排序不能为空'
                        },
                        stringLength: {/*长度提示*/
                            min: 1,
                            max: 100,
                            message: '排序长度必须在1到100之间'
                        }/*最后一个没有逗号*/
                    }
                }
            }
            // 还有一个比较常用的就是submitHandler属性，它对应着提交按钮的事件方法。
            // submitHandler: function (validator, form, submitButton) {
                //alert("submit");
               /*  var menu_name = $("input[name='menu_name']").val();
                var link = $("input[name='link']").val();
                var ico = $("input[name='ico']").val();
                $.ajax({
                    url : '/Admin/Category/addMenu',
                    type : 'get',
                    data : {'menu_name' : menu_name, 'link' : link, 'ico':ico},
                    dataType : 'json',
                    success : function(data){
                      alert(data.message);
                    }
                }); */
           // }
        });
});

//修改菜单
function editGroup(obj){
	var group_id = $(obj).attr('group_id');
	var group_title = $(obj).attr('group_title');
	$('#myModal').modal('show');
	$("#defaultForm").attr('action','/Admin/Category/editUserGroup?id='+group_id);
	$("input[name='title']").val(group_title);
}

// window.onload=setTotal();	

//删除
function deleteCategory(obj,cid){
	layer.confirm('确定要删除数据吗',{btn:['确认','取消'], icon:3, closeBtn: 2 },function(index){
		$.ajax({
			url : '/Admin/Category/deleteCategory',
			data : {'cid':cid},
			type : 'get',
			dataType : 'json',
			async : false,   //取消同步，执行完之后再往下执行
			success : function(data){
				if(data.status == 1){				
					layer.msg(''+data.message+'',{icon:2,time:1000});
				}else if(data.status == 2){
					layer.msg(''+data.message+'',{icon:1,time:1000});
					$(obj).parent('li').parent('ul').parent('div').parent('td').parent('tr').remove();
				}else if(data.status == 3){
					layer.msg(''+data.message+'',{icon:2,time:1000});
				} 
			}
		});
	});	
}
</script>

<script>
$(function(){
	return false;
	var aTr = $('#categoryTable tbody tr');
	var aUnfold = $('.unfold');
	aTr.each(function(){
		//取得class名称
		var level = $(this).attr('level');
		if(level>1){
			$(this).addClass('hide');
		}
	});
	var i = 1;
	aUnfold.click(function(){
		if(i == 1){
			var aSonList = getSonList.call(this);
			if(aSonList.size()){
				$(this).html('-');
				aSonList.removeClass('hide');
			}
			i = 2;
		}else if(i == 2){
			var aSonList = getSonList.call(this);
			if(aSonList.size()){
				$(this).html('+');
				aSonList.addClass('hide');
			}	
			i = 1;
		}
	});
	
	/**** 获取子集列表  ****/
	function getSonList(){
		var oParent = $(this).parents('tr');
		var pid = oParent.attr('cid');
		var sClass = '.pid_'+pid;
		return $('#categoryTable tbody').find(sClass);
	}
	
	
});
</script>
</body>
</html>